/*
 * @Author jiangzhiwei
 * @Date 2023-07-23 18:31:41
 * @LastEditors jiangzhiwei
 * @LastEditTime 2023-07-31 02:37:27
 * @FilePath \test-cron\src\components\yc-cron\components\panes\week-pane\index.js
 * @Description 周面板
 */
import { defineComponent, markRaw } from 'vue-demi'
import { emitValue } from '../../../utils/componentutil'
import { DEFAULT_WEEK_DESCRIPTIONS, getStartDayValueOfWeek, getWeekMap, parseConfig } from '../../../utils/config'
import { WEEK_EXPRESSION_EMIT_NAME } from '../../../utils/constant'
import { h } from '../../../utils/domutil'
import paneMixin from '../mixins/panemixin'
import CommonPerOption from '../../options/common-per-option'
import CommonDurationOption from '../../options/common-duration-option'
import CommonStartOption from '../../options/common-start-option'
import CommonWeekDayOption from '../../options/common-week-day-option'
import CommonLastWeekOption from '../../options/common-last-week-option'
import CommonDesignateOption from '../../options/common-designate-option'
import CommonNotDesignateOption from '../../options/common-not-designate-option'

const NAME = 'yc-cron-day-pane'

export default defineComponent({
  name: NAME,
  mixins: [paneMixin],
  data () {
    /** 可选多少日 */
    const total = 7
    /** 开始数字 */
    const startNum = getStartDayValueOfWeek(this.type)
    const valueMap = getWeekMap(this.type)
    return {
      /** 各个选项的配置信息 */
      options: [
        { label: markRaw(CommonPerOption) },
        { label: markRaw(CommonDurationOption), props: { total, startNum, valueMap } },
        { label: markRaw(CommonStartOption), props: { total, startNum, valueMap } },
        { label: markRaw(CommonWeekDayOption), props: { type: this.type } },
        { label: markRaw(CommonLastWeekOption), props: { type: this.type } },
        { label: markRaw(CommonDesignateOption), props: { total, startNum, valueMap } },
        { label: markRaw(CommonNotDesignateOption), props: { exp: '?' } }
      ]
    }
  },
  computed: {
    descriptions () {
      return parseConfig(DEFAULT_WEEK_DESCRIPTIONS, { day: '日', month: '月', week: '周' })
    }
  },
  methods: {
    /** cron表达式发生变化后 */
    afterExpressionChange (expression) {
      emitValue(this, expression, WEEK_EXPRESSION_EMIT_NAME)
    }
  },
  render () {
    return h('ul', this.generateOptionNodes())
  }
})
